<?php

/** 
 * @todo 写日志类
 * @author Star.li
 * @copyright FZD
 * @update 2011-12-10
 */
class logs {
	//TODO - Insert your code here
	static function write($name,$content){
		$filePath = LOGS_ROOT.$name;
		$fp = fopen($filePath, "a+");
		$size = filesize($filePath);
		
		if($size > LOGS_MAX){
			//归旧
			$backupPath = LOGS_ROOT."history/";
			$ext = explode('.',$name);
			if(!is_dir($backupPath)){
				mkdir($backupPath,0777);
			}
			$backupPath .= $ext[0]."_".date('YmdHis').".".$ext[1];
			if(copy($filePath,$backupPath)){
				$fp = fopen($filePath, "w+");
			}
		}
		
		//$content = date('Y-m-d H:i:s')."\r\n".$content."\r\n";
		$content = $content."\r\n";
		fputs($fp, $content, strlen($content));
		fclose($fp);
	}
}

?>